package edu.langnan.xiaoli.service.impl;

import edu.langnan.xiaoli.constant.XiaoLiConstants;
import edu.langnan.xiaoli.core.domain.PermDO;
import edu.langnan.xiaoli.core.domain.RoleDO;
import edu.langnan.xiaoli.service.PermService;
import edu.langnan.xiaoli.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author cql
 */
@Service
public class PermissionService {

    @Autowired
    private RoleService roleService;

    @Autowired
    private PermService permService;

    /**
     * @param stuID
     * @return
     */
    public Set<String> getRoleOfStudent(Integer stuID) {
        List<RoleDO> roleDOList = roleService.findRoleByUserId(stuID, XiaoLiConstants.STUDENT);
        Set<String> roleNames = new HashSet<>();

        for (RoleDO roleDO : roleDOList) {
            // 获取的是角色字符串，不是角色名称
            roleNames.add(roleDO.getKey());
        }

        return roleNames;
    }

    /**
     * @param stuID
     * @return
     */
    public Set<String> getPermOfStudent(Integer stuID) {
        List<PermDO> permDOList = permService.findPermByStudentId(stuID);
        Set<String> permNames = new HashSet<>();

        for (PermDO permDO : permDOList) {
            permNames.add(permDO.getPerm());
        }

        return permNames;
    }
}
